<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <include file="Public:resource"/>
    <title>个人信息</title>
</head>
<body>
<style>
</style>
<div class="container">
    <include file="Public:top" title="个人信息"/>

    <div class="row form-row" align="left" style="margin-top: 30px;">
        <div class="col-xs-3 col-md-3 col-sm-3 col-lg-3 align-to-input medium">
            姓名
        </div>
        <div class="col-xs-9 col-md-9 col-sm-9 col-lg-9">
            <input type="text" value="{$infoModel.name}" id="name">
            <input type="text" value="{$infoModel.name}" id="name-old" hidden="hidden">
        </div>
    </div>
    <div class="row form-row" align="left">
        <div class="col-xs-3 col-md-3 col-sm-3 col-lg-3 align-to-input medium">
            手机
        </div>
        <div class="col-xs-9 col-md-9 col-sm-9 col-lg-9">
            <input type="text" value="{$infoModel.phone}" id="phone">
            <input type="text" value="{$infoModel.phone}" id="phone-old" hidden="hidden">
        </div>
    </div>
    <div class="row form-row" align="left">
        <div class="col-xs-3 col-md-3 col-sm-3 col-lg-3 align-to-input medium">
            邮箱
        </div>
        <div class="col-xs-9 col-md-9 col-sm-9 col-lg-9">
            <input type="text" value="{$infoModel.email}" id="email">
            <input type="text" value="{$infoModel.email}" id="email-old" hidden="hidden">
        </div>
    </div>

    <div class="row form-row" style="margin-top: 20px;">
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <input type="button" class="btn btn-lg btn-block jss-button"
                   onclick="onModify() " value="提交修改"/>
        </div>
    </div>
</div>

<include file="Public:progress" hint="修改中..."/>
<include file="Public:message"/>
<script>
    function checkSame(){
        if($("#name-old").val().trim() == $("#name").val().trim() &&
           $("#phone-old").val().trim() == $("#phone").val().trim() &&
           $("#email-old").val().trim() == $("#email").val().trim()
            ){
            alert("无修改!");
            return false;
        }
        return true;
    }
    //修改信息
    function onModify() {
        if (!checkInfo('name', 'phone', 'email')) {
            return;
        }
        if(!checkSame()){
            return;
        }
        var email = $("#email").val();
        if(email != ''){
            var emailPattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
            if(!emailPattern.test(email)){
                alert("请填写正确的邮箱");
                return;
            }
        }
        showProgress();
        var param = {
            name: $("#name").val(),
            phone: $("#phone").val(),
            email: $("#email").val()
        }
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: param,
            url: "{:U('Account/modify')}",
            contentType: "application/x-www-form-urlencoded; charset=utf-8",
            success: function (json) {
                hideProgress();
                if (json.status == 'success') {
                    showMessage(json.msg, 3000);
                } else {
                    alert(json.msg);
                }
            },
            error: function (msg) {
                hideProgress();
                alert("修改失败,请检查网络!");
            }
        });
    }
</script>
</body>
</html>